#ifndef __CUserDailyTask_h__
#define __CUserDailyTask_h__

#include "CTArray.h"
#include "../item/CDropItem.h"
#include "CDailyTaskConfig.h"
#include "../cmdfront/cmddailytask.h"

class CDailyTaskIdStatusData
{
public:
    int _iTaskId;
    int _iCount;
    int _iTaskClassType;
    CDailyReflushShort  _stYesterdayTaskFinish;     //记录此任务昨日的完成次数
    short _iFindYesterdayOp;        //0:今天没有做过找回操作, >0:今天做找回操作时的已经完成次数
};

class CDailyTaskMgr;

class CUserDailyTask
{
    friend class CDailyTaskMgr;
public:
	CUserDailyTask() : _uiGID(0)
    {
	}

	virtual ~CUserDailyTask() 
    {
	}

    void Clean();

    static size_t CountSize();

    int Init(const char* sBuff);

    int InitData(CDailyTaskUserData& stUserTaskData);
    int GetData(CDailyTaskUserData& stUserTaskData);

    int GetCurLiveness();

    int GetTBoxStatusWithId(unsigned int iTBoxId);

    int OpenTBoxWithId(unsigned int iTBoxId);

    int OpenClassTBoxWithId(int iTBoxClassTypeId);

    int GetYesterdayFinishId(int iTaskId);

    int UpdateClassTypeFinish(int _iTaskBelong);

    int FindYesterdayTask(int iTaskId);
   
    int GetIntimacyValue();

    int GetSecretaryLevel();

    void SetIntimacyLevel(int iNewSecretaryLevel);
    /*bool IsTaskFinished(CTaskID& stTaskID);

    void DumpTaskInfo();
    void DumpTriggerInfo();
*/
    void SetUserGid(unsigned int uiGid);
    unsigned int GetUserGid() const;

    int GetTaskAwardItems(CDailyTaskTboxAwardConfigData& curTaskCfgData, CSecretaryLevelConfigData& curLevelCfgData, CDropItem& stDropItem, bool bDoubleAward=false);

    int GetClassTBoxStatusWithId(int iTBoxClassTypeId);

    int GetTaskClassAwardItems(CDailyTaskClassAwardConfigData& curTaskCfgData, CDropItem& stDropItem);

    int GetLiveValuer() { return this->_iLiveValuer; }

    int GetFinishCountsWithId(int iTaskId);

    int DiyLuckDoubleAwardBox(int& iFucklyBoxId);

    int GetRandomRange(int iMin, int iMax);

    //GM set task lineness 
    int GMSetDailyTask(int iLiveness, int iTBoxId);

    //完成任务
    int TriggerTaskFinish(unsigned int iTaskID, int iCount = 1);

    int GetCurrentFinishCounts(unsigned int iTaskID);

    int BuySecretaryStyle( int iSecretaryStyle, int iNeedGold );

    int ResetData();

    int CheckDailyTaskUpdate();

private:
    /*
    //升级触发
    int TriggerLevelUp(int iNowLevel);

    //宠物等级上升触发
    int TriggerPetLevelUp(int iNowPetLevel);

    //消灭BOSS
    int TriggerConquerBoss(int iBossID, int iCount);

    //消灭怪物
    int TriggerKillEnemy(int iEnemyID, int iCount);

    //进行操作
    int TriggerDoSomeOpt(int iOptID, int iCount);
    
    //使用道具
    int TriggerUseItem(unsigned char ucItemType, unsigned short usItemID, int iCount);

    //获得道具
    int TriggerGetItem(unsigned char ucItemType, unsigned short usItemID, int iCount);

    //通关
    int TriggerFinishInstance(int iInstanceID, int iCount);
*/

    //task list update, send new status to front
    int UpdateTaskList2Front();

    //check task target status and send new status to front
    int UpdateTaskStatus(bool bSendToFront=true);

    void UpdateTBoxStatus(int iNewLivess);

private:
    unsigned int                                                _uiGID;                     
    bool                                                        m_bTaskTargetStatus;        //record the task status change 
    int m_UpdateTime;                   //上次更新时间

    int _iLiveValuer;   //活跃度
    CTLib::CTArray<int, MAX_TBOX_NUM> _aOpenedTBox; //记录宝箱id开启状况, 0:当前不可开启, 1:可开启, 2:已经开启
    CTLib::CTHashObjectMgr<int, CDailyTaskIdStatusData>  _hTaskCounts; //任务的完成次数, taskid->counts
    CTLib::CTArray<int, MAX_DAILY_TASK_CLASS_CONFIG>   _aClassTypeAwardeds; //每个类型是否已经给予奖励

    CDailyReflushShort  _stDailyLivess;     //每日小秘书活跃度领取标志，同时可做是否同一天记录
    CSecretaryData   _stSecretary;          //小秘书数据
};


#endif // __CUserDailyTask_h__

